/**
 * <b>项目名：</b>hclv-web<br/>
 * <b>包名：</b>com.flea.hclv.service.impl<br/>
 * <b>文件名：</b>HServiceOrderImpl.java<br/>
 * <b>版本信息：</b>1.0<br/>
 * <b>日期：</b>2018年11月16日 上午11:58:55<br/>
 * <b>COPYRIGHT 2010-2012 ALL RIGHTS RESERVED 虫子科技</b>-版权所有<br/>
 */
package com.flea.hclv.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.flea.hclv.constant.HConstant;
import com.flea.hclv.model.dao.*;
import com.flea.hclv.model.entity.*;
import com.flea.hclv.model.entity.vo.HVisitorOderQueryVo;
import com.flea.hclv.service.HServiceOrderService;
import com.flea.hclv.util.HclvDictUtil;
import com.flea.hclv.util.ServerResponse;
import com.flea.system.base.util.StringUtil;
import com.flea.system.bean.FleaPage;
import com.flea.system.entity.OrgDept;
import com.flea.system.entity.OrgUser;
import com.flea.system.entity.WebDict;
import com.flea.system.platform.session.FleaOrgUtils;
import com.flea.system.utils.FleaStringUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.collections.CollectionUtils;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @description
 * @createTime 2018年11月16日 上午11:58:55
 * @modifyTime
 * @author myflea@163.com
 * @version 1.0
 */
@Service
public class HServiceOrderServiceImpl implements HServiceOrderService {

    private Logger logger = LoggerFactory.getLogger(HServiceOrderServiceImpl.class);
    @Autowired
    private HServiceOrderMapper hServiceOrderMapper;
    @Autowired
    private HTravelGroupMapper hTravelGroupMapper;
    @Autowired
    private HTourGroupVisitorMapper hTourGroupVisitorMapper;
    @Autowired
    private HVisitorMapper hVisitorMapper;
    @Autowired
    private HServiceOrderUpdateApplyMapper hServiceOrderUpdateApplyMapper;
    @Autowired
    private HServiceOrderUpdateRecoderMapper hServiceOrderUpdateRecoderMapper;
    @Autowired
    private HServicePayRebackItemMapper hServicePayRebackItemMapper;

    @Override
    public ServerResponse<HServiceOrder> addOrder(HttpServletRequest request, String groupId) throws Exception {
        String curId = FleaOrgUtils.getCurUserUuid(request);
        String serviceOrg = FleaOrgUtils.getCurrentUserDeptUuid(request);

        //HTravelGroup group = JSONObject.parseObject(model, HTravelGroup.class);

        if (null == groupId || "".equals(groupId)) {
            logger.info("团信息不完整，无法创建订单,团Id:{}",groupId);
            return ServerResponse.createByErrorMessage("团信息不完整，无法创建订单");
        }
        //String groupId = group.getId();

        HTravelGroup oldGroup = hTravelGroupMapper.selectByPrimaryKey(groupId);
        if (null == oldGroup) {
            logger.error("团不存在，无法创建订单.团Id:{}",groupId);
            return ServerResponse.createByErrorMessage("团不存在，无法创建订单");
        }

        //判读是否已经未封团状态，不是封团状态的不可以下单
        if (!HConstant.HCLV_VISITOR_GROUP_ISYES.equals(oldGroup.getStatus())) {
            String statusName = "";
            List<WebDict> listStatus = HclvDictUtil.getTravelGroupStatus();
            if (listStatus != null) {
                for (WebDict dict : listStatus
                        ) {
                    if (dict.getDictCode().equals(oldGroup.getStatus())) {
                        statusName = dict.getDictName();
                        break;
                    }
                }
            }
            logger.error("此团状态为:{},不可以下单，请确认已经封团",statusName);
            return ServerResponse.createByErrorMessage("此团状态为:" + statusName + "不可以下单，请确认已经封团");
        }
        //判断订单并未创建
        HServiceOrder tempOrder;
        boolean resultExite = this.findByGroupId(groupId).isSuccess();
        if (resultExite) {
            tempOrder = this.findByGroupId(groupId).getData();
            if (null != tempOrder) {
                logger.info("此团已经下单，不可重复下单,订单：{}",tempOrder);
                return ServerResponse.createByErrorMessage("此团已经下单，不可重复下单");
            }
        } else {
            logger.error("异常,团不存在，团Id:{}",groupId);
            throw new Exception("异常");
        }


        HServiceOrder entity = new HServiceOrder();
        entity.setId(FleaStringUtils.getGenerateUUID());
        entity.setCreateUser(curId);
        entity.setGroupId(groupId);
        entity.setModifuUser(curId);
        entity.setOrderNo("HS" + FleaStringUtils.getOrderIdByTime());
        entity.setPayStatus(HConstant.D_HCLV_D_SERVICE_ORDER_STATIC_WAIT_CONFIRM);
        entity.setServiceOrgId(serviceOrg);
        // 计算一个团所有付款多少钱，班期的成本价*人数
        entity.setShouldPayment(oldGroup.getTotelCost());
        //
        // entity.setStatus("");
        // 设置供应商id
        entity.setSupplerOrgId(oldGroup.getSupplierId());
        entity.setTimeTableId(oldGroup.getTimeTableId());

        boolean result = hServiceOrderMapper.insertSelective(entity) == 1;

        if (!result) {
            logger.error("创建订单失败,服务订单：{}",entity);
            throw new Exception("创建订单失败");

        } else {
            logger.info("创建服务订单成功，服务订单：{}",entity);
            return ServerResponse.createBySuccessMessage("创建订单成功");
        }
    }

    @Override
    public ServerResponse<FleaPage<HServiceOrder>> findAllOrderByOrgIdPagingForSale(
            HttpServletRequest request, int curPage, int pageSize,
            String model) throws Exception {
        HVisitorOderQueryVo vo = JSON.parseObject(model, HVisitorOderQueryVo.class);
        RowBounds rowBounds = new RowBounds(curPage, pageSize);
        String orgId = FleaOrgUtils.getCurrentUserDeptUuid(request);

        List<HServiceOrder> orders = hServiceOrderMapper.findByOrgIdAndSatusAndOrderNoForSale(rowBounds, orgId, vo);


        FleaPage<HServiceOrder> pages = new FleaPage<>(orders);
        // coverCodeToName
        List<HServiceOrder> newOders = this.coverCodeToName(orders);
        pages.setCurPageData(newOders);

        return ServerResponse.createBySuccess("操作成功", pages);
    }

    private List<HServiceOrder> coverCodeToName(List<HServiceOrder> orders) {
        List<HServiceOrder> list = new ArrayList<>();
        for (HServiceOrder sho : orders) {
//            HServiceOrder temp = new HServiceOrder();
            OrgDept serverOrgDept = FleaOrgUtils.getOrgDeptByDeptUuid(sho.getServiceOrgId());
            if (null != serverOrgDept) {
                sho.setServerName(serverOrgDept.getDeptName());
            } else {
                sho.setServerName(null);
            }
            OrgDept supplierOrg = FleaOrgUtils.getOrgDeptByDeptUuid(sho.getSupplerOrgId());
            if (null != supplierOrg) {
                sho.setSplierName(supplierOrg.getDeptName());
            } else {
                sho.setSplierName(null);
            }
            HTravelGroup g = hTravelGroupMapper.selectByPrimaryKey(sho.getGroupId());
            if (null != g) {
                sho.setGroupName(g.getGroupName());
            }
            list.add(sho);
        }

        return list;
    }


    @Override
    public ServerResponse<Map<String, Object>> findByOrderId(String serviceOrderId) {
        HServiceOrder order = hServiceOrderMapper.selectByPrimaryKey(serviceOrderId);
        // coverCodeToName
        String supperName = HclvDictUtil.coverOrgCodeToName(order.getSupplerOrgId());
        String serviceName = HclvDictUtil.coverOrgCodeToName(order.getServiceOrgId());
        order.setServerName(serviceName);
        order.setSplierName(supperName);
        List<HTourGroupVisitor> visitorsRelation = hTourGroupVisitorMapper.selectByGroupId(order.getGroupId());
        List<String> visitorIds = Lists.newArrayList();
        List<HVisitor> hVisitors = null;
        if (CollectionUtils.isNotEmpty(visitorsRelation)){
            for (HTourGroupVisitor visitors : visitorsRelation){
                visitorIds.add(visitors.getVisitorId());
            }
            hVisitors = hVisitorMapper.findByIds(visitorIds);
        }
        Map<String,Object> dataMap = Maps.newHashMap();
        dataMap.put("order",order);
        dataMap.put("visitors",hVisitors);
        logger.info("服务订单详情：{}",order);
        return ServerResponse.createBySuccess(dataMap);
    }

    @Override
    public ServerResponse<HServiceOrder> updateOrder(
            HttpServletRequest request, String model) throws Exception {
        String curUserId = FleaOrgUtils.getCurUserUuid(request);
        String curOrgId = FleaOrgUtils.getCurrentUserDeptUuid(request);
        if (StringUtil.isEmpty(model)) {
            logger.error("更新信息为空，不可更改,model数据:{}",model);
            return ServerResponse.createByErrorMessage("更新信息为空，不可更改");
        }
        JSONObject jsb = JSONObject.parseObject(model);
        if (null == jsb) {
            logger.error("更新信息为空，不可更改,model数据:{}",model);
            return ServerResponse.createByErrorMessage("更新信息为空，不可更改");
        }
        String applyId = jsb.getString("applyId");
        Float updateMoney = jsb.getFloat("updateMoney");
        if (StringUtil.isEmpty(applyId)) {
            logger.error("申请ID为空，不可进行更新");
            return ServerResponse.createByErrorMessage("申请ID为空，不可进行更新");
        }
        if (null == updateMoney) {
            logger.error("申请修改的总金额非法，不可进行更新");
            return ServerResponse.createByErrorMessage("申请修改的总金额非法，不可进行更新");
        }
        HServiceOrderUpdateApply apply = hServiceOrderUpdateApplyMapper.selectByPrimaryKey(applyId);
        if(null==apply){
          return ServerResponse.createByErrorMessage("未找到相关的申请，不可进行修改");
        }
      if(!HConstant.D_HCLV_D_SERVICE_ORDER_UPDATE_ALLPY_TYPE_UPDATE_PRODUCT.equals(apply.getType())){
        return ServerResponse.createByErrorMessage("此申请不是订单修改申请，不可进行订单修改操作");
      }
        // 如果申请未被同意，则不能进行修改
        if (!apply.getStatus().equals(HConstant.D_HCLV_D_SERVICE_ORDER_UPDATE_ALLPY_STATE_AGREE)) {
            logger.info("该修改申请未被同意，不能进行修改");
            return ServerResponse.createByErrorMessage("该修改申请未被同意，不能进行修改");
        }


        HServiceOrder oldOrder = hServiceOrderMapper.findByOrderNo(apply.getServerOrderNo());


        if (null == oldOrder) {
            logger.error("订单已经不存在，请重新确认");
            return ServerResponse.createByErrorMessage("订单已经不存在，请重新确认");
        }
        if (oldOrder.getPayStatus().equals(HConstant.D_HCLV_D_SERVICE_ORDER_STATIC_OK_CLOSE)) {
            logger.info("改服务订单已经完成，不可进行修改,订单：{}",oldOrder);
            return ServerResponse.createByErrorMessage("该订单已经完成，不可进行修改");
        }

        // 确认订单修改信息，只可修改订单总价

        Float oldOrderShouldPayment = oldOrder.getShouldPayment();

        Float oldOrderActualPayment = oldOrder.getActualPayment();

        oldOrder.setModifuUser(curOrgId);

        // 是供应商，地接社
        boolean isSuppier = curOrgId.equals(oldOrder.getSupplerOrgId());
        // 是组团社
        boolean isGroupOrg = curOrgId.equals(oldOrder.getServiceOrgId());
        // 更新非法，没有修改订单的权限
        if (!isSuppier && !isGroupOrg) {
            logger.error("非法操作，没有订单修改权限,供应商id:{},组团社Id:{}",oldOrder.getSupplerOrgId(),oldOrder.getServiceOrgId());
            return ServerResponse.createByErrorMessage("非法操作，没有订单修改权限");
        }

        // 总价修改之后，判断是否需要进行退款 1、组团社要让供应商退款 2、组团社需要向供应商继续付款
        // 判断订单修改人是组团社还是地接社
        // 1、订单总金额是增加了还是减少了

        if (updateMoney - oldOrderShouldPayment == 0) {
            logger.info("订单没有变化，无需进行修改,订单：{}",oldOrder);
            return ServerResponse.createByErrorMessage("订单没有变化，无需进行修改");
            // 不用进行退款，支付金额一样，不进行任何操作，前端判断
        }
        // 订单总金额增加
        if (updateMoney - oldOrderShouldPayment > 0) {
            // 判断实际支付金额，以及现在订单的状态
            // 供应商进行修改
            if (isSuppier) {
                //
                oldOrder.setPayStatus(HConstant.D_HCLV_D_SERVICE_ORDER_STATIC_PARTPRY);
            }
            // 组团社进行修改
            if (isGroupOrg) {
                // Float tempresultMoney =
                // updateTotelMoney-oldOrderActualPayment;

                oldOrder.setPayStatus(HConstant.D_HCLV_D_SERVICE_ORDER_STATIC_PARTPRY);

            }
        }
        // 订单总金额减少
        if (updateMoney - oldOrderShouldPayment < 0) {
            // 判断支付金额，订单状态，如果订单状态为已经完成，更改订单状态

            // 供应商进行修改
            if (isSuppier) {
                //
                oldOrder.setPayStatus(HConstant.D_HCLV_D_SERVICE_ORDER_STATIC_PARTPRY);
                Float tempresultMoney = updateMoney
                        - oldOrderActualPayment;
                // 进入退款流程
//                if (tempresultMoney > 0) {
//                    // TODO
//                    HServicePayRebackItem recoder = new HServicePayRebackItem();
//                    recoder.setCode(FleaStringUtils.getGenerateUUID());
//                    recoder.setCreateUser(curUserId);
//                    recoder.setId(FleaStringUtils.getGenerateUUID());
//                    recoder.setOrderNo(oldOrder.getOrderNo());
//                    recoder.setPayOrgId(curOrgId);
//                    recoder.setRebackMoney(tempresultMoney);
//
//                    recoder.setReceiveId(oldOrder.getServiceOrgId());
//                    boolean rebackResult = goRebackMoney(recoder);
//                    if (!rebackResult) {
//                        logger.error("设置退款记录失败");
//                        throw new Exception("设置退款记录失败！");
//                    }
//
//                }
                // 组团社进行修改
                if (isGroupOrg) {
                    // 继续付款就行了

                    oldOrder.setPayStatus(HConstant.D_HCLV_D_SERVICE_ORDER_STATIC_PARTPRY);

                }
            }
        }
        oldOrder.setShouldPayment(updateMoney);

        boolean result = hServiceOrderMapper.updateByPrimaryKeySelective(oldOrder) == 1;
        if (!result) {
            logger.error("更新服务订单异常，订单：{}",oldOrder);
            throw new Exception("更新订单记录出现异常，请联系运维人员");
        }
        apply.setModifyUser(curUserId);
        apply.setStatus(HConstant.D_HCLV_D_SERVICE_ORDER_UPDATE_ALLPY_STATE_WC);
        result = hServiceOrderUpdateApplyMapper.updateByPrimaryKeySelective(apply)==1;
      if (!result) {
        logger.error("更新服务订单异常，订单：{}",oldOrder);
        throw new Exception("更新申请状态完成，请联系运维人员");
      }

        logger.info("更新服务订单成功：{}",oldOrder);
        // 更新订单
        // 插入更新记录表
        HServiceOrderUpdateRecoder updateRecoder = new HServiceOrderUpdateRecoder();
        updateRecoder.setApplerId(applyId);
        updateRecoder.setCreateUser(curUserId);
        updateRecoder.setId(FleaStringUtils.getGenerateUUID());
        updateRecoder.setModifyUser(curUserId);
        updateRecoder.setUpdateInfoBefore(JSONObject.toJSONString(oldOrder));
        updateRecoder.setUpdateInfoAfter(JSONObject.toJSONString(oldOrder));
        updateRecoder.setUpdateOrgId(curOrgId);
        OrgUser our = FleaOrgUtils.getCurUser(request);
        updateRecoder.setUpdateUserName(our.getUserName());

        hServiceOrderUpdateRecoderMapper.insertSelective(updateRecoder);

        return ServerResponse.createBySuccessMessage("操作成功");
    }

    @Override
    public ServerResponse<HServiceOrder> findByGroupId(String groupId) throws Exception {
        HServiceOrder result = hServiceOrderMapper.findByGroupId(groupId);
        return ServerResponse.createBySuccess(result);
    }

    @Override
    public ServerResponse<HServiceOrder> findByOrderNo(String orderNo) throws Exception {
        HServiceOrder order = hServiceOrderMapper.findByOrderNo(orderNo);
        if (null != order) {
            List<HServiceOrder> list = new ArrayList<>();
            list.add(order);
            order = this.coverCodeToName(list).get(0);
        }

        return ServerResponse.createBySuccess(order);
    }

    @Override
    public ServerResponse<HServiceOrder> updateOrderToConfirm(HttpServletRequest request,
                                                              String serviceNo) throws Exception {
      //geshi hua
        if (StringUtil.isEmpty(serviceNo)) {
            logger.error("参数非法,服务订单号：{}",serviceNo);
            return ServerResponse.createByErrorMessage("参数非法");
        }
        HServiceOrder serviceOrder = hServiceOrderMapper.findByOrderNo(serviceNo);
        if (null == serviceOrder) {
            logger.error("该服务订单已经不存在，服务订单号：{}",serviceNo);
            return ServerResponse.createByErrorMessage("该订单已经不存在了");
        }
        String userId = FleaOrgUtils.getCurUserUuid(request);
        String serviceOrderStatus = serviceOrder.getPayStatus();
//        String serviceOrgId = serviceOrder.getServiceOrgId();
        String suppilerOrgId = serviceOrder.getSupplerOrgId();
        String orgId = FleaOrgUtils.getCurrentUserDeptUuid(request);

        if (!orgId.equals(suppilerOrgId)) {
            logger.error("该操作非法，没有权限");
            return ServerResponse.createByErrorMessage("该操作非法，没有权限");
        }


        if (!HConstant.D_HCLV_D_SERVICE_ORDER_STATIC_WAIT_CONFIRM.equals(serviceOrderStatus)) {
            logger.info("该服务订单已被确认，不可进行多次操作，订单：{}",serviceOrder);
            return ServerResponse.createByErrorMessage("该订单已被确认，不可进行多次操作");
        }
        serviceOrder.setPayStatus(HConstant.D_HCLV_D_SERVICE_ORDER_STATIC_WAIT_PAY);
        serviceOrder.setModifuUser(userId);

        boolean result = hServiceOrderMapper.updateByPrimaryKeySelective(serviceOrder) == 1;
        if (!result) {
            logger.error("订单确认失败,订单详情：{}",serviceOrder);
            throw new Exception("订单确认失败，请联系系统管理员");
        }
        logger.info("服务订单确认操作成功，订单详情：{}",serviceOrder);
        return ServerResponse.createBySuccessMessage("订单确认操作成功");
    }

    @Override
    public ServerResponse<HServiceOrder> updateOrderToClose(HttpServletRequest request, String serviceNo)
            throws Exception {
        if (StringUtil.isEmpty(serviceNo)) {
            logger.error("参数非法,服务的订单号：{}",serviceNo);
            return ServerResponse.createByErrorMessage("参数非法");
        }
        HServiceOrder serviceOrder = hServiceOrderMapper.findByOrderNo(serviceNo);
        if (null == serviceOrder) {
            logger.error("该服务订单已经不存在，服务订单号：{}",serviceNo);
            return ServerResponse.createByErrorMessage("该订单已经不存在了");
        }
        String userId = FleaOrgUtils.getCurUserUuid(request);
        String serviceOrderStatus = serviceOrder.getPayStatus();
//        String serviceOrgId = serviceOrder.getServiceOrgId();
//        String suppilerOrgId = serviceOrder.getSupplerOrgId();
//        String orgId = FleaOrgUtils.getCurrentUserDeptUuid(request);


        if (!HConstant.D_HCLV_D_SERVICE_ORDER_STATIC_WAIT_CONFIRM.equals(serviceOrderStatus)) {
            logger.info("该服务订单已被确认，不可进行关闭操作,订单详情：{}",serviceOrder);
            return ServerResponse.createByErrorMessage("该订单已被确认，不可进行关闭操作");
        }
        serviceOrder.setPayStatus(HConstant.D_HCLV_D_SERVICE_ORDER_STATIC_COLOSE);
        serviceOrder.setModifuUser(userId);

        boolean result = hServiceOrderMapper.updateByPrimaryKeySelective(serviceOrder) == 1;
        if (!result) {
            logger.error("服务订单关闭失败,订单详情：{}",serviceOrder);
            throw new Exception("订单关闭失败，请联系系统管理员");
        }
        logger.info("服务订单关闭成功，订单详情：{}",serviceOrder);
        return ServerResponse.createBySuccessMessage("订单关闭操作成功");
    }

    @Override
    public ServerResponse<HServiceOrder> updateOrderToFinish(HttpServletRequest request, String serviceNo)
            throws Exception {
        if (StringUtil.isEmpty(serviceNo)) {
            logger.error("参数非法,服务订单号：{}",serviceNo);
            return ServerResponse.createByErrorMessage("参数非法");
        }
        HServiceOrder serviceOrder = hServiceOrderMapper.findByOrderNo(serviceNo);
        if (null == serviceOrder) {
            logger.error("服务订单不存在，服务订单号：{}",serviceNo);
            return ServerResponse.createByErrorMessage("该订单已经不存在了");
        }
        String userId = FleaOrgUtils.getCurUserUuid(request);
        String serviceOrderStatus = serviceOrder.getPayStatus();
//        String serviceOrgId = serviceOrder.getServiceOrgId();
//        String suppilerOrgId = serviceOrder.getSupplerOrgId();
//        String orgId = FleaOrgUtils.getCurrentUserDeptUuid(request);


        if (!HConstant.D_HCLV_D_SERVICE_ORDER_STATIC_PAT_ALL.equals(serviceOrderStatus)) {
            logger.info("该服务订单未支付完成，不可订单完成操作，订单详情：{}",serviceOrder);
            return ServerResponse.createByErrorMessage("该订单未支付完成，不可订单完成操作");
        }
        serviceOrder.setPayStatus(HConstant.D_HCLV_D_SERVICE_ORDER_STATIC_OK_CLOSE);
        serviceOrder.setModifuUser(userId);

        boolean result = hServiceOrderMapper.updateByPrimaryKeySelective(serviceOrder) == 1;
        if (!result) {
            logger.error("更新服务订单为完成状态失败，订单详情：{}",serviceOrder);
            throw new Exception("订单完成失败，请联系系统管理员");
        }
        logger.info("更新服务订单为完成状态成功，订单详情：{}",serviceOrder);
        return ServerResponse.createBySuccessMessage("订单完成操作成功");
    }

  @Override
  public ServerResponse<FleaPage<HServiceOrder>> findAllOrderByOrgIdPagingForBuy(
      HttpServletRequest request, int curPage, int pageSize, String model) throws Exception {
    {
      HVisitorOderQueryVo vo = JSON.parseObject(model, HVisitorOderQueryVo.class);
      RowBounds rowBounds = new RowBounds(curPage, pageSize);
      String orgId = FleaOrgUtils.getCurrentUserDeptUuid(request);

      List<HServiceOrder> orders = hServiceOrderMapper.findByOrgIdAndSatusAndOrderNoForBuy(rowBounds, orgId, vo);


      FleaPage<HServiceOrder> pages = new FleaPage<>(orders);
      // coverCodeToName
      List<HServiceOrder> newOders = this.coverCodeToName(orders);
      pages.setCurPageData(newOders);

      return ServerResponse.createBySuccess("操作成功", pages);
    }
  }

  @Override
  public ServerResponse findByTimeTableId(String timeTableId, HttpServletRequest request,
      int curPage, int pageSize) throws Exception {
      if(StringUtil.isEmpty(timeTableId)){
        return ServerResponse.createByErrorMessage("班期ID为空");
      }
      RowBounds bounds = new RowBounds(curPage,pageSize);
      List<HServiceOrder> result =  hServiceOrderMapper.findByTimeTableId(timeTableId,bounds);
      FleaPage<HServiceOrder> page = new FleaPage<>(result);
      result = coverCodeToName(result);
      page.setCurPageData(result);
      return ServerResponse.createBySuccess(page);
  }

  @Override
  public List<HServiceOrder> findByTimeTableIdToList(String timeTableId) throws Exception {
    List<HServiceOrder> result =  hServiceOrderMapper.findByTimeTableIdToList(timeTableId);
    return result;
  }

    /*private boolean goRebackMoney(HServicePayRebackItem recoder) {
        return hServicePayRebackItemMapper.insertSelective(recoder) == 1;

    }*/

}
